package org.ky.generator.expand;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
 * 基本JSON对象，若需要JSON数据返回，则继承该类，保证返回数据
 * 
 * @author K.y
 *
 */
@JsonInclude(value = Include.NON_NULL) // 如果为空则不参加序列化
public class BaseJson implements IJsonHandler {
	private static final long serialVersionUID = 1L;
	protected Logger logger = Logger.getLogger(this.getClass());

	@Override
	public String toJson() {
		try {
			return JSON.toJSONString(this);
		} catch (Exception e) {
			logger.error("Transform JavaBean to Json string is exception.", e);
		}
		return null;
	}

	@Override
	public String toString() {
		return toJson();
	}
}
